package com.cskaoyan.config2;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * @author stone
 * @date 2022/06/24 15:13
 */
@Configuration
public class DataSourceConfiguration2 {

    // 直接赋值，魔法值
    //String driverClass = "com.mysql.jdbc.Driver";
    //String jdbcUrl = "jdbc:mysql://localhost:3306/cskaoyan_db?useUnicode=true&characterEncoding=utf-8";
    //String username = "root";
    //String password = "123456";

    //@Value("com.mysql.jdbc.Driver")
    //String driverClass;
    //@Value("jdbc:mysql://localhost:3306/cskaoyan_db?useUnicode=true&characterEncoding=utf-8")
    //String jdbcUrl;
    //@Value("root")
    //String username;
    //@Value("123456")
    //String password;

    @Value("${cskaoyan.datasource.driverClass}")
    String driverClass;
    @Value("${cskaoyan.datasource.url}")
    String jdbcUrl;
    @Value("${cskaoyan.datasource.username}")
    String username;
    @Value("${cskaoyan.datasource.password}")
    String password;

    @Bean
    public DataSource dataSource2() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName(driverClass);
        dataSource.setUrl(jdbcUrl);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        return dataSource;
    }
}
